# -*- coding: utf-8 -*-
# @Time    : 2021/12/5 22:14
# @Email   : 849080458@qq.com
# @Author  : zgh
# @FileName: day07_request.py
# @Software: PyCharm

# 从今开始，使用gitee，进行提交：2021年12月7日 14:22:54
import os.path
import time

from flask import Flask, request, render_template
from flask.views import View

app = Flask(__name__)


@app.route('/')
def index():
    return render_template('../class9_flask基本结构/templates/index.html')

# 作业内容
@app.route('/uploads/', methods=['POST'])
def upload():
    # 获取图片
    file = request.files.get('pic')
    if not file:
        return render_template('../class9_flask基本结构/templates/index.html')
    file_name = time.struct_time('%Y-%m-%d-%H-%M-%S') + file.filename
    file_url = f'/static/{file_name}'
    file.save(os.path.join(app.root_path, app.static_folder, file_name))
    return file_url


"""
@app.route('/', methods=['GET', 'POST'])
def index():
    a = request
    # get 请求  request 请求相关，flask app wsgi:环境变量   代理模式
    get_data = request.args
    # 表单
    form_data = request.form
    # json  header{applocation/json}
    json_data = request.json
    # file
    file_data = request.files
    # AJAX ,json  请求头：XHR
    return 'index'
"""

if __name__ == '__main__':
    app.run(debug=True)
